package com.dylan.springcloud.common.util;

import java.util.Map;
import java.util.function.Supplier;

/**
 * Created by Dylan on 2018/8/17.
 */
public class MapBuilder<K, V> {

    private Map<K, V> map;

    public static <K1, V1> MapBuilder<K1, V1> createBuilder(Supplier<? extends Map<K1, V1>> supplier) {
        MapBuilder<K1, V1> builder = new MapBuilder<>();
        builder.map = supplier.get();
        return builder;
    }

    public Map<K, V> build() {
        return this.map;
    }

    public int size() {
        return map.size();
    }

    public boolean isEmpty() {
        return map.isEmpty();
    }

    public MapBuilder<K, V> put(K key, V value) {
        map.put(key, value);
        return this;
    }

    public MapBuilder<K, V> remove(K key) {
        map.remove(key);
        return this;
    }

    public MapBuilder<K, V> putAll(Map<? extends K, ? extends V> m) {
        map.putAll(m);
        return this;
    }

    public MapBuilder<K, V> putIfAbsent(K key, V value) {
        map.putIfAbsent(key, value);
        return this;
    }

}
